<?php
/**
 * 信息
 */
namespace ServS\Map;

use think\Db;
class BaidDuMap{
	/**
	 * 接口获取地理位置
	 */
	public function getdress($ip){
		$badp = require CON_PATH.'baiduapk.php';
		$url =$badp['url'].$ip."&ak=".$badp['ak']."&coor=".$badp['coor'];
		$result = @file_get_contents($url);
		// $ip = @file_get_contents("http://ip.taobao.com/service/getIpInfo.php?ip=".$ip);
		$result = json_decode($result,true);
		// $url = "http://api.map.baidu.com/location/ip?ak=omi69HPHpl5luMtrjFzXn9df&ip=$ip&coor=bd09ll";
		// $ch = curl_init();
		// curl_setopt($ch, CURLOPT_URL, $url);
		// curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		// $output = curl_exec($ch);
		// dd($output);
		return $result;
	}

	/**
	 * 坐标获取地理信息
	 */
	public function getbylatlnt($lat,$lnt){
		$badp = require CON_PATH.'baiduapk.php';
		$url = "http://api.map.baidu.com/geocoder/v2/?callback=renderReverse&coordtype=bd09ll&location=".$lat.",".$lnt."&output=json&pois=1&ak=".$badp['ak'];
		$result = @file_get_contents($url);
		$result = preg_replace("/renderReverse&&renderReverse/", '',$result);
		$result = substr($result,1);
		$result = substr($result,0,strlen($result)-1); 
		$result = json_decode($result,true);
		
		return $result;
	}
}